/**
 * Define support functions
 * @author: snipe@crebird.com
 */
CrebirdUtils = function(options) {
  this.init(options);
}

$.extend(CrebirdUtils.prototype, {
  options: '',

  init: function(options) {
    if (options) 
      this.options = options;
  },

  /**
   * Validate null or empty or undefined
   * @author: snipe@crebird.com
   */
  isNullOrEmpty: function(str) {
    if (str == null || str == '' || str === undefined) {
      return true;
    }

    return false;
  },

  /**
   * Validate date format (dd/yy/mmmm)
   * @author: snipe@crebird.com
   */
  isDate: function(inputDate) {
    var objDate, mSeconds, day, month, year;

    if (inputDate.length !== 10) { 
        return false; 
    } 

    if (inputDate.substring(2, 3) !== '/' || inputDate.substring(5, 6) !== '/') { 
        return false; 
    } 

    day = inputDate.substring(0, 2) - 1;
    month = inputDate.substring(3, 5) - 0; 
    year = inputDate.substring(6, 10) - 0; 

    if (year < 1000 || year > 3000) { 
        return false; 
    } 

    mSeconds = (new Date(year, month, day)).getTime(); 

    objDate = new Date(); 
    objDate.setTime(mSeconds); 

    if (objDate.getFullYear() !== year || 
        objDate.getMonth() !== month || 
        objDate.getDate() !== day) { 
        return false; 
    } 

    return true; 
  },

  /**
   * Validate email format
   * @author: snipe@crebird.com
   */
  isEmail: function(email) {
    var re = /\S+@\S+\.\S+/;
    return re.test(email);
  },

  isJson : function(str) {
    var json = null;

    try {
      json = JSON.parse(str);
    } catch (exception) {
      json = null;
      return false;
    }

    return json;
  },
});

var util = new CrebirdUtils();
